<template>
  <div class="tab-bar-item" @click="itemClick">
    <slot v-if="isActive" name="item-icon"></slot>
    <slot v-else name="item-icon-active"></slot>
    <div :style="{color: !isActive ? color: ''}">
      <slot name="item-text"></slot>
    </div>
  </div>
</template>

<script>
  export default {
    props: {
      path: String,
      color: {
        type: String,
        default() {
          return "red"
        }
      }
    },
    computed: {
      isActive() {
        return this.$route.path.indexOf(this.path)
      }
    },
    methods: {
      itemClick() {
        this.$router.push(this.path)
      }
    },
  }
</script>

<style scoped>
  .tab-bar-item {
    flex: 1;
    text-align: center;
    height: 49px;
    font-size: 12px;
  }
  .tab-bar-item img {
    width: 20px;
    height: 20px;
    margin: 5px 0;
    vertical-align: middle;
  }
  .active {
    color: red;
  }
</style>